home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 301-325 / disk_313 / uucp / uucp1.lzh / src / lib / getpwnam.c < prev    next >
C/C++ Source or Header  |  1990-01-14  |  2KB  |  102 lines

  1.  
  2. /*
  3.  *  GETPWNAM.C
  4.  *
  5.  *  (C) Copyright 1989-1990 by Matthew Dillon,  All Rights Reserved.
  6.  *
  7.  *  (UUCP source support)
  8.  */
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <pwd.h>
  13.  
  14. static char *Breakout();
  15.  
  16. char *PasswdFile = "UULIB:passwd";
  17.  
  18. struct passwd *
  19. getpwnam(name)
  20. char *name;
  21. {
  22.     FILE *fi = fopen(PasswdFile, "r");
  23.     char *buf = malloc(256);
  24.     static char User[32];
  25.     static char Passwd[32];
  26.     static char Dir[128];
  27.     static char Shell[256];
  28.     static struct passwd Pas = { User, Passwd, 0, 0, 0, "", "", Dir, Shell };
  29.  
  30.     if (fi == NULL)
  31.     return(NULL);
  32.  
  33.     while (fgets(buf, 256, fi)) {
  34.     char *ptr = buf;
  35.     char *arg;
  36.  
  37.     arg = Breakout(&ptr);
  38.     if (strcmp(name, arg) != 0)
  39.         continue;
  40.     strcpy(Pas.pw_name, arg);
  41.     strcpy(Pas.pw_passwd, Breakout(&ptr));
  42.     Pas.pw_uid = atoi(Breakout(&ptr));
  43.     Pas.pw_gid = atoi(Breakout(&ptr));
  44.     Breakout(&ptr);     /*  finger info */
  45.     strcpy(Pas.pw_dir, Breakout(&ptr));
  46.     strcpy(Pas.pw_shell, Breakout(&ptr));
  47.  
  48.     {
  49.         short i = strlen(Pas.pw_dir) - 1;
  50.         if (i >= 0 && Pas.pw_dir[i] != ':' && Pas.pw_dir[i] != '/') {
  51.         Pas.pw_dir[i++] = '/';
  52.         Pas.pw_dir[i] = 0;
  53.         }
  54.     }
  55.  
  56.     {
  57.         char *str;
  58.  
  59.         Pas.pw_shell_arg0 = Pas.pw_shell;
  60.         for (str = Pas.pw_shell; *str && *str != ' ' && *str != 9; ++str);
  61.         if (*str) {
  62.         *str = 0;
  63.         ++str;
  64.         while (*str == ' ' || *str == 9)
  65.             ++str;
  66.         Pas.pw_shell_argn = str;
  67.         } else {
  68.         Pas.pw_shell_argn = str;
  69.         }
  70.     }
  71.  
  72.  
  73.     fclose(fi);
  74.     return(&Pas);
  75.     }
  76.     fclose(fi);
  77.     return(NULL);
  78. }
  79.  
  80. static
  81. char *
  82. Breakout(pptr)
  83. char **pptr;
  84. {
  85.     char *base;
  86.     char *ptr;
  87.  
  88.     base = *pptr;
  89.     if (base == NULL)
  90.     return("");
  91.     for (ptr = base; *ptr && *ptr != '\n' && *ptr != ','; ++ptr);
  92.     if (*ptr == ',') {
  93.     *pptr = ptr + 1;
  94.     *ptr = 0;
  95.     } else {
  96.     *pptr = NULL;
  97.     *ptr = 0;
  98.     }
  99.     return(base);
  100. }
  101.  
  102.